﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHANHDONG.Excercise.Bai2
{
    public partial class MayTinhCamTay : Form
    {
        public MayTinhCamTay()
        {
            InitializeComponent();
        }

        private void MayTinhCamTay_Load(object sender, EventArgs e)
        {
            cmbPhepTinh.Items.Add("Cộng");
            cmbPhepTinh.Items.Add("Trừ");
            cmbPhepTinh.Items.Add("Nhân");
            cmbPhepTinh.Items.Add("Chia");
            cmbPhepTinh.SelectedIndex = 0;
        }

        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            erpLoi.Clear();

            if(string.IsNullOrEmpty(txtSoThu1.Text))
            {
                erpLoi.SetError(txtSoThu1, "Khong dc de trong !!");
                txtSoThu1.Focus();
            }
            else
            {
                if(string.IsNullOrEmpty(txtSoThu2.Text))
                {
                    erpLoi.SetError(txtSoThu2, "khong dc de trong !!");
                    txtSoThu2.Focus();
                }
                else
                {
                    Calculator cal;
                    CONTROLLERS con = new CONTROLLERS();

                    if(cmbPhepTinh.Text == "Cộng")
                    {
                        cal = new Calculator(double.Parse(txtSoThu1.Text), double.Parse(txtSoThu2.Text), 0);
                        txtKetQua.Text = con.KiemTra(cal) + " ";
                    }
                    else if (cmbPhepTinh.Text == "Trừ")
                    {
                        cal = new Calculator(double.Parse(txtSoThu1.Text), double.Parse(txtSoThu2.Text), 1);
                        txtKetQua.Text = con.KiemTra(cal) + " ";
                    }
                    else if (cmbPhepTinh.Text == "Nhân")
                    {
                        cal = new Calculator(double.Parse(txtSoThu1.Text), double.Parse(txtSoThu2.Text), 2);
                        txtKetQua.Text = con.KiemTra(cal) + " ";
                    }
                    else if (cmbPhepTinh.Text == "Chia")
                    {
                        cal = new Calculator(double.Parse(txtSoThu1.Text), double.Parse(txtSoThu2.Text), 3);
                        txtKetQua.Text = con.KiemTra(cal) + " ";
                    }

                    
                    
                }
            }
        }
    }
}
